package com.example.lets;

import com.andexert.library.RippleView;
import com.baidu.mapapi.SDKInitializer;
import com.bmob.BmobConfiguration;
import com.bmob.BmobPro;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// ��ʹ��SDK�����֮ǰ��ʼ��context��Ϣ������ApplicationContext
		// ע��÷���Ҫ��setContentView����֮ǰʵ��
		SDKInitializer.initialize(getApplicationContext());
		setContentView(R.layout.activity_main);

		// ��ʼ��Bmob SDK
		Bmob.initialize(this, "13f0e49d5141ecd8ba0aa06f484e7e34");

		User curUser = BmobUser.getCurrentUser(this, User.class);
		if (curUser != null) {
			// ��ʼ�����û��Ļ���·��


			if (curUser.getAge() == null || curUser.getGender() == null || curUser.getNickname() == null) {
				Toast.makeText(MainActivity.this, "请完善您的个人信息", Toast.LENGTH_SHORT).show();
				Intent intent = new Intent();
				intent.setClass(MainActivity.this, CompleteInfoActivity.class);
				startActivity(intent);
				MainActivity.this.finish();
			}

			else {
				BmobConfiguration config = new BmobConfiguration.Builder(this)
						.customExternalCacheDir(curUser.getUsername()).build();
				BmobPro.getInstance(this).initConfig(config);
				Intent intent = new Intent();
				intent.setClass(MainActivity.this, HomeActivity.class);
				startActivity(intent);
				MainActivity.this.finish();
			}
		}

		RippleView loginRippleView = (RippleView) findViewById(R.id.main_login);
		loginRippleView.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
			@Override
			public void onComplete(RippleView rippleView) {
				Intent intent = new Intent();
				intent.setClass(MainActivity.this, LoginActivity.class);
				startActivity(intent);
//				MainActivity.this.finish();
			}
		});

		//loginRippleView.setFrameRate(60);
		loginRippleView.setRippleDuration(100);
		//loginRippleView.setZoomScale(50.0f);

		RippleView registerRippleView = (RippleView) findViewById(R.id.main_register);
		registerRippleView.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
			@Override
			public void onComplete(RippleView rippleView) {
				Intent intent = new Intent();
				intent.setClass(MainActivity.this, RegisterActivity.class);
				startActivity(intent);
//				MainActivity.this.finish();
			}
		});

		//registerRippleView.setFrameRate(60);
		//registerRippleView.setZoomScale(5.0f);
		registerRippleView.setRippleDuration(100);
		registerRippleView.getRippleColor();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
